package com.credithc.customers.base.ro;

import com.credithc.customers.base.codes.CustomerCodes;
import com.credithc.customers.base.exception.CustomerException;
import com.credithc.customers.base.utils.CustomerUtils;
import lombok.Data;
import org.apache.commons.lang.StringUtils;

/**
 * @description: 客户登录入参表
 * @author: fby
 * @date: 2019/05/21 17:22
 * @param: null
 * @return:
 */
@Data
public class CustomerUnifyLoginRo extends CustomerBaseRo {

    private String phone;

    private String password;

    private String smsCode;

    private String extend;

    private String verify;

    private String invitationCode;

    public static void checkBaseParam(CustomerUnifyLoginRo ro) {
        if (StringUtils.isBlank(ro.getPhone())) {
            throw new CustomerException(CustomerCodes.PARAM_VALIDATE_ERROR, "登录名不能为空");
        }
        if (StringUtils.isBlank(ro.getRequestNo())) {
            throw new CustomerException(CustomerCodes.PARAM_VALIDATE_ERROR, "请求流水号不能为空");
        }
        if (StringUtils.isBlank(ro.getSmsCode())) {
            if (StringUtils.isBlank(ro.getPassword())) {
                throw new CustomerException(CustomerCodes.PARAM_VALIDATE_ERROR, "验证码和密码不能同时为空");
            } /*else {
                throw new CustomerException(CustomerCodes.PARAM_VALIDATE_ERROR, "验证码不能为空");
            }*/
        }
        CustomerUtils.checkPhone(ro.getPhone());
        if (StringUtils.isNotBlank(ro.getPassword())) {
            CustomerUtils.checkPassword1(ro.getPassword());
        }
    }

}
